Nick Dylla
7/30/2019
x <- 2 # read as "assign x to be a value of 2"
y <- 10 # read as "assign y to be a value of 10"
print(x + y) # read as "show me what x plus y equals"## [1] 12
## # A tibble: 6 x 7
## `First Name` `Last Name` Gender Country Age Date Id
## <chr> <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 Dulce Abril Female United States 32 15/10/2017 1562
## 2 Mara Hashimoto Female Great Britain 25 16/08/2016 1582
## 3 Philip Gent Male France 36 21/05/2015 2587
## 4 Kathleen Hanner Female United States 25 15/10/2017 3549
## 5 Nereida Magwood Female United States 58 16/08/2016 2468
## 6 Gaston Brumm Male United States 24 21/05/2015 2554
-Thesis link: https://harvest.usask.ca/bitstream/handle/10388/11889/DYLLA-THESIS-2019.pdf?sequence=1&isAllowed=y
library(plotly)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv')
df$q <- with(df, cut(pop, quantile(pop)))
levels(df$q) <- paste(c("1st", "2nd", "3rd", "4th", "5th"), "Quantile")
df$q <- as.ordered(df$q)
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showland = TRUE,
landcolor = toRGB("gray85"),
subunitwidth = 1,
countrywidth = 1,
subunitcolor = toRGB("white"),
countrycolor = toRGB("white")
)
p <- plot_geo(df, locationmode = 'USA-states', sizes = c(1, 250)) %>%
add_markers(
x = ~lon, y = ~lat, size = ~pop, color = ~q, hoverinfo = "text",
text = ~paste(df$name, "<br />", df$pop/1e6, " million")
) %>%
layout(title = '2014 US city populations<br>(Click legend to toggle)', geo = g)
pdata <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv")
data_2007 <- data[which(data$year == 2007),]
data_2007 <- data_2007[order(data_2007$continent, data_2007$country),]
data_2007$size <- data_2007$pop
colors <- c('#4AC6B7', '#1972A4', '#965F8A', '#FF7070', '#C61951')
pl <- plot_ly(data_2007, x = ~gdpPercap, y = ~lifeExp, z = ~pop, color = ~continent, size = ~size, colors = colors,
marker = list(symbol = 'circle', sizemode = 'diameter'), sizes = c(5, 150),
text = ~paste('Country:', country, '<br>Life Expectancy:', lifeExp, '<br>GDP:', gdpPercap,
'<br>Pop.:', pop)) %>%
layout(title = 'Life Expectancy v. Per Capita GDP, 2007',
scene = list(xaxis = list(title = 'GDP per capita (2000 dollars)',
gridcolor = 'rgb(255, 255, 255)',
range = c(2.003297660701705, 5.191505530708712),
type = 'log',
zerolinewidth = 1,
ticklen = 5,
gridwidth = 2),
yaxis = list(title = 'Life Expectancy (years)',
gridcolor = 'rgb(255, 255, 255)',
range = c(36.12621671352166, 91.72921793264332),
zerolinewidth = 1,
ticklen = 5,
gridwith = 2),
zaxis = list(title = 'Population',
gridcolor = 'rgb(255, 255, 255)',
type = 'log',
zerolinewidth = 1,
ticklen = 5,
gridwith = 2)),
paper_bgcolor = 'rgb(243, 243, 243)',
plot_bgcolor = 'rgb(243, 243, 243)')
pl